"""
用户信息表
"""
from datetime import datetime
from common.models import db


class UserBase(db.Model):
    """
    用户基本信息
    """
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True, doc='用户ID')
    account = db.Column(db.String(32), doc='账号')
    phone = db.Column(db.String(16), doc='手机号')
    password = db.Column(db.String(256), doc='密码')
    user_name = db.Column(db.String(32), doc='昵称')
    profile_photo = db.Column(db.String(64), doc='头像')
    last_login = db.Column(db.DateTime, doc='最后登录时间')
    address = db.Column(db.String(128), doc='地址')
    is_superuser = db.Column(db.Integer, default=0, doc='0普通用户1管理员2超级管理员')
    register_time = db.Column(db.DateTime, doc='注册时间', default=datetime.now)
    appkey_id = db.Column(db.String(32), doc='app key')
    secret = db.Column(db.String(32), doc='盐')

    @classmethod
    def get_user_by_appkey_id(cls, appkey_id):
        return cls.query.filter_by(appkey_id=appkey_id).first()
